<?php
define("MAX_PATH",				260);
define("MAX_MODULE_NAME32",		255);
define("TH32CS_SNAPPROCESS",	2);
define("TH32CS_SNAPMODULE",		0x10);
define("INVALID_HANDLE_VALUE",	-1);
define("PROCESS_ALL_ACCESS",	0x000F0000 | 0x00100000 | 0xFFF);

include "./lib/dll.class.php";
$kernel32 = new windll('kernel32.dll');
echo "\n\nprocess                  pid  thread    ppid \n--------------------------------------------\n";
foreach(GetProcessList() as $process)
{
	//print_r($process);exit;
	printf("%-20s %7d %7d %7d\n",$process['exefile'],$process['process_id'],$process['count_threads'],$process['parent_process_id']);
}

function GetProcessList( )
{
	global $kernel32;

	// Take a snapshot of all processes in the system.
	$hProcessSnap = $kernel32->CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if( $hProcessSnap == INVALID_HANDLE_VALUE )
	{
		trigger_error("CreateToolhelp32Snapshot (of processes)");
		return false;
	}
	$pe32 = pack('V9',296,0,0,0,0,0,0,0,0).str_repeat("\0",MAX_PATH);
	
	// Retrieve information about the first process,
	// and exit if unsuccessful
	if( !$kernel32->Process32First( array($hProcessSnap, &$pe32 ) ) )
	{
		echo $kernel32->GetLastError();
		trigger_error( "Process32First" );			// Show cause of failure
		$kernel32->CloseHandle( $hProcessSnap );	// Must clean up the
													// snapshot object!
		return false;
	}

	// Now walk the snapshot of processes
	do
	{
		$exefile = substr($pe32,36);
		$exefile = substr($exefile,0,strpos($exefile,"\0"));
		$pe32_t = unpack("Vsize/Vusage/Vprocess_id/Vdefault_heap_id/Vmodule_id/Vcount_threads/Vparent_process_id/Vpriority_base/Vflags",$pe32);
		$pe32_t['exefile'] = $exefile;
		$ret[] = $pe32_t;
	} while( $kernel32->Process32Next( array($hProcessSnap, &$pe32) ) );
	
	$kernel32->CloseHandle( $hProcessSnap );
	return $ret;
}
if(php_sapi_name()=='cli')system("pause");